package com.cvo.scrumtoolkit.client.pannels;

import com.cvo.scrumtoolkit.client.controller.ControllerImpl;
import com.cvo.scrumtoolkit.client.controller.View;
import com.cvo.scrumtoolkit.client.entities.LoadedProject;
import com.cvo.scrumtoolkit.client.entities.Project;
import com.cvo.scrumtoolkit.client.model.ProjectStore;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ProjectStorePanel extends Composite{
	private ControllerImpl controller;
	private ProjectStore projectStore;
	private static ProjectStorePanelUiBinder uiBinder = GWT
			.create(ProjectStorePanelUiBinder.class);

	interface ProjectStorePanelUiBinder extends
			UiBinder<Widget, ProjectStorePanel> {
	}

		

	@UiField
	VerticalPanel verticalPanel;
	
	public ProjectStorePanel() {
		initWidget(uiBinder.createAndBindUi(this));
		projectStore=ProjectStore.getProjectStore();
		
		for (final Project project:projectStore.getProjects()){
			final Button projectButton = new Button(project.getProjectname());
			verticalPanel.add(projectButton);
			projectButton.addClickHandler(new ClickHandler() {
				
				@Override
				public void onClick(ClickEvent event) {
					try {
						ControllerImpl.getController().changeView(View.PROJECTBACKLOG, project.getId().toString(), null);
						LoadedProject.getLoadedProject().setProjectId(project.getId().toString());
					} catch (Exception ex) {
						// TODO Auto-generated catch block
					}	
					
				}
			});
		}
		
	}

	
}
